﻿using System;
using System.Collections;
using System.Collections.Generic;

namespace UniRx.Operators
{
	// Token: 0x0200035D RID: 861
	internal class ZipObservable<T1, T2, T3, T4, T5, T6, T7, TR> : OperatorObservableBase<TR>
	{
		// Token: 0x060011A8 RID: 4520 RVA: 0x0005114C File Offset: 0x0004F54C
		public ZipObservable(IObservable<T1> source1, IObservable<T2> source2, IObservable<T3> source3, IObservable<T4> source4, IObservable<T5> source5, IObservable<T6> source6, IObservable<T7> source7, ZipFunc<T1, T2, T3, T4, T5, T6, T7, TR> resultSelector) : base(source1.IsRequiredSubscribeOnCurrentThread<T1>() || source2.IsRequiredSubscribeOnCurrentThread<T2>() || source3.IsRequiredSubscribeOnCurrentThread<T3>() || source4.IsRequiredSubscribeOnCurrentThread<T4>() || source5.IsRequiredSubscribeOnCurrentThread<T5>() || source6.IsRequiredSubscribeOnCurrentThread<T6>() || source7.IsRequiredSubscribeOnCurrentThread<T7>())
		{
			this.source1 = source1;
			this.source2 = source2;
			this.source3 = source3;
			this.source4 = source4;
			this.source5 = source5;
			this.source6 = source6;
			this.source7 = source7;
			this.resultSelector = resultSelector;
		}

		// Token: 0x060011A9 RID: 4521 RVA: 0x000511F1 File Offset: 0x0004F5F1
		protected override IDisposable SubscribeCore(IObserver<TR> observer, IDisposable cancel)
		{
			return new ZipObservable<T1, T2, T3, T4, T5, T6, T7, TR>.Zip(this, observer, cancel).Run();
		}

		// Token: 0x04000A7F RID: 2687
		private IObservable<T1> source1;

		// Token: 0x04000A80 RID: 2688
		private IObservable<T2> source2;

		// Token: 0x04000A81 RID: 2689
		private IObservable<T3> source3;

		// Token: 0x04000A82 RID: 2690
		private IObservable<T4> source4;

		// Token: 0x04000A83 RID: 2691
		private IObservable<T5> source5;

		// Token: 0x04000A84 RID: 2692
		private IObservable<T6> source6;

		// Token: 0x04000A85 RID: 2693
		private IObservable<T7> source7;

		// Token: 0x04000A86 RID: 2694
		private ZipFunc<T1, T2, T3, T4, T5, T6, T7, TR> resultSelector;

		// Token: 0x0200035E RID: 862
		private class Zip : NthZipObserverBase<TR>
		{
			// Token: 0x060011AA RID: 4522 RVA: 0x00051200 File Offset: 0x0004F600
			public Zip(ZipObservable<T1, T2, T3, T4, T5, T6, T7, TR> parent, IObserver<TR> observer, IDisposable cancel) : base(observer, cancel)
			{
				this.parent = parent;
			}

			// Token: 0x060011AB RID: 4523 RVA: 0x00051274 File Offset: 0x0004F674
			public IDisposable Run()
			{
				base.SetQueue(new ICollection[]
				{
					this.q1,
					this.q2,
					this.q3,
					this.q4,
					this.q5,
					this.q6,
					this.q7
				});
				IDisposable disposable = this.parent.source1.Subscribe(new ZipObserver<T1>(this.gate, this, 0, this.q1));
				IDisposable disposable2 = this.parent.source2.Subscribe(new ZipObserver<T2>(this.gate, this, 1, this.q2));
				IDisposable disposable3 = this.parent.source3.Subscribe(new ZipObserver<T3>(this.gate, this, 2, this.q3));
				IDisposable disposable4 = this.parent.source4.Subscribe(new ZipObserver<T4>(this.gate, this, 3, this.q4));
				IDisposable disposable5 = this.parent.source5.Subscribe(new ZipObserver<T5>(this.gate, this, 4, this.q5));
				IDisposable disposable6 = this.parent.source6.Subscribe(new ZipObserver<T6>(this.gate, this, 5, this.q6));
                IDisposable disposable7 = this.parent.source7.Subscribe(new ZipObserver<T7>(this.gate, this, 6, this.q7));
                return StableCompositeDisposable.Create(new IDisposable[]
				{
					disposable,
					disposable2,
					disposable3,
					disposable4,
					disposable5,
					disposable6,
					disposable7,
					Disposable.Create(delegate
					{
						object obj = this.gate;
						lock (obj)
						{
							this.q1.Clear();
							this.q2.Clear();
							this.q3.Clear();
							this.q4.Clear();
							this.q5.Clear();
							this.q6.Clear();
							this.q7.Clear();
						}
					})
				});
			}

			// Token: 0x060011AC RID: 4524 RVA: 0x0005140C File Offset: 0x0004F80C
			public override TR GetResult()
			{
				return this.parent.resultSelector(this.q1.Dequeue(), this.q2.Dequeue(), this.q3.Dequeue(), this.q4.Dequeue(), this.q5.Dequeue(), this.q6.Dequeue(), this.q7.Dequeue());
			}

            // Token: 0x060011AD RID: 4525 RVA: 0x00051476 File Offset: 0x0004F876
            public override void OnNext(TR value)
            {
                this.observer.OnNext(value);
            }

            // Token: 0x060011AE RID: 4526 RVA: 0x00051488 File Offset: 0x0004F888
            public override void OnError(Exception error)
			{
				try
				{
					this.observer.OnError(error);
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x060011AF RID: 4527 RVA: 0x000514C0 File Offset: 0x0004F8C0
			public override void OnCompleted()
			{
				try
				{
					this.observer.OnCompleted();
				}
				finally
				{
					base.Dispose();
				}
			}

			// Token: 0x04000A87 RID: 2695
			private readonly ZipObservable<T1, T2, T3, T4, T5, T6, T7, TR> parent;

			// Token: 0x04000A88 RID: 2696
			private readonly object gate = new object();

			// Token: 0x04000A89 RID: 2697
			private readonly Queue<T1> q1 = new Queue<T1>();

			// Token: 0x04000A8A RID: 2698
			private readonly Queue<T2> q2 = new Queue<T2>();

			// Token: 0x04000A8B RID: 2699
			private readonly Queue<T3> q3 = new Queue<T3>();

			// Token: 0x04000A8C RID: 2700
			private readonly Queue<T4> q4 = new Queue<T4>();

			// Token: 0x04000A8D RID: 2701
			private readonly Queue<T5> q5 = new Queue<T5>();

			// Token: 0x04000A8E RID: 2702
			private readonly Queue<T6> q6 = new Queue<T6>();

			// Token: 0x04000A8F RID: 2703
			private readonly Queue<T7> q7 = new Queue<T7>();
		}
	}
}
